﻿setTimeout(() => {
	console.log('成功加修仙突破科学家 (⓿_⓿)')

	_wts.createSubgrade()
	_wts.setTitle('修仙突破')

	const saveGameButton = document.querySelector('#localSaveBtn')
	const contentLayer = _wts.getContainer()
	const config = {
		increase: 10 ** 16, // 每次增加的资源数量
	}

	const table = {
		'灵石': 'money',
		'经验': 'xp',
		'遗物点': 'legacyPoints',
	}

	// 根据名字设置 cookie 里面的数值
	const setCookie = (cname, cvalue, exdays) => {
		const d = new Date()
		d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000))
		const expires = "expires=" + d.toUTCString()
		document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"
	}

	// 根据名字读储存在 cookie 里面的数值
	const getCookie = (cname) => {
		const name = cname + "="
		const decodedCookie = decodeURIComponent(document.cookie)
		let ca = decodedCookie.split(';')
		for (let i = 0; i < ca.length; i++) {
			let c = ca[i]
			while (c.charAt(0) == ' ') {
				c = c.substring(1)
			}
			if (c.indexOf(name) == 0) {
				return c.substring(name.length, c.length)
			}
		}
		return ""
	}

	// 创建按钮
	const createAllAddButton = () => {
		const domCache = []
		for (let cnNameKey in table) {
			const btn = generateButton(cnNameKey)

			domCache.push(btn)
		}

		for (let dom of domCache) {
			contentLayer.appendChild(dom)
		}
	}

	// 保存游戏
	const saveGameAllData = () => {
		saveGameButton.click()
	}

	// 生成一个按钮并返回
	const generateButton = (cnName) => {
		const btn = document.createElement('button')
		const title = `来 ${formatSize(config.increase)} ${cnName}`
		btn.innerText = title
		btn.style.margin = 3 + 'px'
		btn.style.fontSize = 10 + 'px'

		btn.onclick = () => {
			saveGameAllData()
			const enName = table[cnName]
			const orivalue = getCookie(enName)
			setCookie(enName, orivalue + config.increase, 1000)
			location.reload()
		}

		return btn
	}

	// 主函数
	const main = () => {
		createAllAddButton()
	}


	main()

}, 1 * 1000)

